package com.strato.queue.v1_0_0.exec;

import com.strato.batch.base.v1_0_0.api.JobExecutionConfig;
import com.strato.batch.base.v1_0_0.api.JobExecutor;
import com.strato.batch.base.v1_0_0.api.JobProducer;
import com.strato.queue.v1_0_0.jdbc.model.QueueMessage;

public class ConsumerExecution<T extends QueueMessage> {

	public void start(){
		executor.execute(producer, config);
	}
	
	public void stop(){
		if(producer!=null){
			if(producer instanceof RoundRobinQueueJobProducer){
				RoundRobinQueueJobProducer qp=(RoundRobinQueueJobProducer) producer;
				qp.setAvailable(false);
			}
		}
	}
	
	private JobProducer<T> producer;
	
	private JobExecutionConfig<T> config;
	
	private JobExecutor<T> executor;

	public JobProducer<T> getProducer() {
		return producer;
	}

	public void setProducer(JobProducer<T> producer) {
		this.producer = producer;
	}

	public JobExecutionConfig<T> getConfig() {
		return config;
	}

	public void setConfig(JobExecutionConfig<T> config) {
		this.config = config;
	}

	public JobExecutor<T> getExecutor() {
		return executor;
	}

	public void setExecutor(JobExecutor<T> executor) {
		this.executor = executor;
	}

}
